﻿using Common;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
             
            ConsoleKeyInfo consoleKeyInfo = new ConsoleKeyInfo();

            //while (consoleKeyInfo.Key == ConsoleKey.Spacebar)
            //{
            //    Console.WriteLine();
            //    Console.WriteLine("Key = " + consoleKeyInfo.Key.ToString());

            //    if (consoleKeyInfo.Key != ConsoleKey.Enter)
            //    {
            //        await ScheduleTask.RunTask(args, 2);
            //    }

            //    if (consoleKeyInfo.Key == ConsoleKey.Enter)
            //        break;

            //    Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss fff}]--------------------------------------------------------------------------");
            //    Console.WriteLine("SPACE BAR TO RUN ONCE.....");
            //    Console.WriteLine("ENTER TO BREAKS.....");

            //    consoleKeyInfo = Console.ReadKey();
            //}

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Key = " + consoleKeyInfo.Key.ToString()); 

                Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss fff}]-++++++----------------------------------------------------------------------");
                Console.WriteLine("SPACE BAR TO RUN ONCE.....");
                Console.WriteLine("ENTER TO BREAKS.....");

                consoleKeyInfo = Console.ReadKey();

                if (consoleKeyInfo.Key != ConsoleKey.Enter && ScheduleTask.InRunning == false)
                {
                    await ScheduleTask.RunTask(args, 1);
                }

                if (consoleKeyInfo.Key == ConsoleKey.Enter)
                    break;
            }

            Console.ReadKey();
            Console.ReadKey();
            Console.ReadKey();
        }
    }
}
